﻿using Common;
using IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DemoManageSys.Areas.Filters;
using Models.DTO;
using Microsoft.AspNetCore.Mvc;
using Models;

namespace DemoManageSys.Areas.API.Controllers
{
    [Area("API")]
    public class OrderInfoController : Controller
    {
        private IOrderInfoBLL _orderInfoInfoBLL;

        public OrderInfoController(
            IOrderInfoBLL orderInfoInfoBLL
            )
        {
            _orderInfoInfoBLL = orderInfoInfoBLL;
        }

        #region 获取的方法 (GetOrderInfoes)
        [HttpGet]
        public IActionResult GetOrderInfo(int page, int limit, string customerId)
        {
            int count;
            //调用BLL的查询方法
            List<GetOrderInfoDTO> getOrderInfoDTOs = _orderInfoInfoBLL.GetOrderInfo(page, limit, customerId, out count);

            ReturnResule result = new ReturnResule()
            {
                Code = 0,
                Msg = "获取成功",
                Data = getOrderInfoDTOs,
                Count = count
            };

            return Json(result);
        }
        #endregion

        #region 获取的方法 (GetOrderInfoes)
        [HttpGet]
        public IActionResult GetOrderInfoTrue(int page, int limit, string customerId)
        {
            int count;
            //调用BLL的查询方法
            List<GetOrderInfoDTO> getOrderInfoDTOs = _orderInfoInfoBLL.GetOrderInfoTrue(page, limit, customerId, out count);

            ReturnResule result = new ReturnResule()
            {
                Code = 0,
                Msg = "获取成功",
                Data = getOrderInfoDTOs,
                Count = count
            };

            return Json(result);
        }
        #endregion 

        #region 添加的方法 (CreateOrderInfo)
        [HttpPost]
        public IActionResult CreateOrderInfo([FromForm] OrderInfo orde)
        {
            //实例化对象
            ReturnResule resule = new ReturnResule();
            string msg;//定义返回消息
            resule.IsSuccess = _orderInfoInfoBLL.CreateOrderInfo(orde, out msg);//调用方法传值
            if (resule.IsSuccess)
            {
                resule.Code = 200;
                resule.Msg = msg;
                resule.Data = orde.Id;
            }
            else
            {
                resule.Msg = msg;
            }
            return Json(resule);
        }
        #endregion

        #region 删除的方法 (DeleteOrderInfo)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult DelOrderInfo(string id)
        {
            //实例化对象
            ReturnResule resule = new ReturnResule();
            if (string.IsNullOrWhiteSpace(id))
            {
                resule.Msg = "删除订单的id不能为空";
                return Json(resule);
            }

            resule.IsSuccess = _orderInfoInfoBLL.DelOrderInfo(id);//调用方法传值
            if (resule.IsSuccess)
            {
                resule.Msg = "删除订单成功";
                resule.Code = 200;
            }
            else
            {
                resule.Msg = "删除订单失败";
            }
            return Json(resule);
        }
        #endregion

        #region 删除的方法 (DeleteOrderInfo)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult DeleteOrderInfo(string id)
        {
            //实例化对象
            ReturnResule resule = new ReturnResule();
            if (string.IsNullOrWhiteSpace(id))
            {
                resule.Msg = "删除订单的id不能为空";
                return Json(resule);
            }

            resule.IsSuccess = _orderInfoInfoBLL.DeleteOrderInfo(id);//调用方法传值
            if (resule.IsSuccess)
            {
                resule.Msg = "删除订单成功";
                resule.Code = 200;
            }
            else
            {
                resule.Msg = "删除订单失败";
            }
            return Json(resule);
        }
        #endregion

        #region 修改商品的方法 (UpdateOrderInfo)
        /// <summary>
        /// 修改商品的方法
        /// </summary>
        /// <param name="dept"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdateOrderInfo([FromForm] OrderInfo dept)
        {
            //实例化对象
            ReturnResule resule = new ReturnResule();

            string msg;//定义返回消息
            resule.IsSuccess = _orderInfoInfoBLL.UpdateOrderInfo(dept, out msg);//调用方法传值

            resule.Msg = msg;
            if (resule.IsSuccess)
            {
                resule.Code = 200;
            }

            return Json(resule);
        }
        #endregion

    }
}